export default {

    state: { //定义数据
        tagInfo: [],
        title: [{
            header: "user",
            icon: "",
            is_header: 0,
            path: "/admin/user/level",
            title: "会员等级"
        }],
        bread: [],
    },
    mutations: { //定义方法
        getTagInfo(state, val) {
            // 判断当前要添加到taginfo的数据 是否已存在 不存在不添加 直接高亮即可 不存在push
            let isPush = state.tagInfo.some((v) => {
                return v.title == val.title
            })
            if (isPush) { //代表当前数据已存在
                state.tagInfo.forEach((v) => {
                    if (v.title == val.title) {
                        state.title = val
                    }
                })
            } else {
                state.title = val
                state.tagInfo.push(val)
            }
        },
        // 删除tag导航
        delTaginfo(state, index) {
            state.tagInfo.splice(index, 1)
            state.title = state.tagInfo[state.tagInfo.length - 1]
        },
        // 完成路由数据的存储
        getTagVal(state, val) {
            state.title = val
        },
        // 面包屑
        getBread(state, val) {
            state.bread = val
        }
    },
    actions: { //异步触发
        getTagInfoAsync(context, val) {
            context.commit("getTagInfo", val) //异步触发
        },
        delTaginfoAsync(context, index) {
            context.commit("delTaginfo", index) //异步触发

        },
        getTagValAsync(context, val) {
            context.commit("getTagVal", val)
        },
        // 面包屑
        getBreadAsync(context, val) {
            context.commit('getBread', val)
        }
    },
    namespaced: true, //添加命名空间
}